package pl.edu.pb.wi.pwnography.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import pl.edu.pb.wi.pwnography.session.FileList;

public class FileModuleInterceptor extends HandlerInterceptorAdapter {
    @Autowired
    private FileList fileList;

    public void setFileList(FileList fileList) {
	this.fileList = fileList;
    }

    @Override
    public boolean preHandle(HttpServletRequest request,
	    HttpServletResponse response, Object handler) throws Exception {
	if (fileList.getActiveFile() == null) {
	    response.sendRedirect(request.getContextPath() + "/");
	    return false;
	} else
	    return super.preHandle(request, response, handler);
    }
}
